﻿#include <iostream>
#include <vector>
#include <string>

bool checkNumber(int val) {
    if (val % 2 == 0) {
        return false;
    }
    for (int i = 2; i <= val / 2 + 1; ++i) {
        if (val % i == 0) {
            return false;
        }
    }
    return true;
}

int result(int val) {

    int vmin = val, vmax = val;
    if (checkNumber(val)) {
        return val;
    }
    else {
        while (true) {
            if (checkNumber(vmin)) {
                return vmin;
            }
            else if (checkNumber(vmax)) {
                return vmax;
            }
            else {
                vmin--;
                vmax++;
            }
        }
    }

}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> array;
    std::string word;
    for (char c : input) {
        if (c == ' ') {
            array.push_back(word);
            word = "";
        }
        else {
            word += c;
        }
    }
    array.push_back(word);

    std::vector<std::string> numbers = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

    bool flag = true;
    if (array[0] == numbers[0] || array.size() < 3) {
        flag = false;
    }
    if (not((array[0] == numbers[1] || array[0] == numbers[2] || array[0] == numbers[3] || array[0] == numbers[4] || array[0] == numbers[5] || array[0] == numbers[6] || array[0] == numbers[7] || array[0] == numbers[8] || array[0] == numbers[9]) && (array[1] == numbers[0] || array[1] == numbers[1] || array[1] == numbers[2] || array[1] == numbers[3] || array[1] == numbers[4] || array[1] == numbers[5] || array[1] == numbers[6] || array[1] == numbers[7] || array[1] == numbers[8] || array[1] == numbers[9]) && (array[2] == numbers[0] || array[2] == numbers[1] || array[2] == numbers[2] || array[2] == numbers[3] || array[2] == numbers[4] || array[2] == numbers[5] || array[2] == numbers[6] || array[2] == numbers[7] || array[2] == numbers[8] || array[2] == numbers[9])))  flag = false;
    
    int res_number = 0;
    if (flag) {
        if (array[0] == numbers[1]) res_number += 100;
        if (array[0] == numbers[2]) res_number += 200;
        if (array[0] == numbers[3]) res_number += 300;
        if (array[0] == numbers[4]) res_number += 400;
        if (array[0] == numbers[5]) res_number += 500;
        if (array[0] == numbers[6]) res_number += 600;
        if (array[0] == numbers[7]) res_number += 700;
        if (array[0] == numbers[8]) res_number += 800;
        if (array[0] == numbers[9]) res_number += 900;

        if (array[1] == numbers[0]) res_number += 0;
        if (array[1] == numbers[1]) res_number += 10;
        if (array[1] == numbers[2]) res_number += 20;
        if (array[1] == numbers[3]) res_number += 30;
        if (array[1] == numbers[4]) res_number += 40;
        if (array[1] == numbers[5]) res_number += 50;
        if (array[1] == numbers[6]) res_number += 60;
        if (array[1] == numbers[7]) res_number += 70;
        if (array[1] == numbers[8]) res_number += 80;
        if (array[1] == numbers[9]) res_number += 90;

        if (array[2] == numbers[0]) res_number += 0;
        if (array[2] == numbers[1]) res_number += 1;
        if (array[2] == numbers[2]) res_number += 2;
        if (array[2] == numbers[3]) res_number += 3;
        if (array[2] == numbers[4]) res_number += 4;
        if (array[2] == numbers[5]) res_number += 5;
        if (array[2] == numbers[6]) res_number += 6;
        if (array[2] == numbers[7]) res_number += 7;
        if (array[2] == numbers[8]) res_number += 8;
        if (array[2] == numbers[9]) res_number += 9;
        std::cout << result(res_number);
    }
    else {
        std::cout << "Wrong input";
    }

    return 0;
}